/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.baicaix.chat.controllers;

import org.baicaix.chat.ChatConstants;
import org.baicaix.chat.ChatMainFacade;
import org.baicaix.chat.views.InternalFrame;
import org.baicaix.chat.views.InternalFrameMediator;
import org.puremvc.java.interfaces.INotification;
import org.puremvc.java.patterns.command.SimpleCommand;

/**
 *
 * @author baicaix
 */
public class InitFrameCommand extends SimpleCommand {

    public InitFrameCommand() {
    }

    @Override
    public void execute(INotification in) {
        super.execute(in);
        //接受两种初始化任务
        System.out.println("InitFrameCommand receive command:"+in.getName());
        if(ChatConstants.SHOW_FRAME_01.equals(in.getName())) {
            showChatFrame01();
        } else if(ChatConstants.SHOW_FRAME_02.equals(in.getName())) {
            showChatFrame02();
        }
    }

    public void showChatFrame01() {
        //通知Mediator创建界面
        InternalFrame inFrame = new InternalFrame("Kissjava");
        createMediator(inFrame);
    }

    private void createMediator(InternalFrame inFrame) {
        facade = ChatMainFacade.getInstance();
        InternalFrameMediator mediator = new InternalFrameMediator(this.toString(), inFrame);
        facade.registerMediator(mediator);
        facade.sendNotification(ChatConstants.CREATE_FRAME, inFrame, null);
    }

    public void showChatFrame02() {
        //通知Mediator创建界面
        InternalFrame inFrame = new InternalFrame("BaiCaiX");
        createMediator(inFrame);
    }
}
